<%@page import="hyl.core.MyFun"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@ include file="pub/top.jsp"%>
<%@ page import="java.util.List,java.util.Map"%>
<%
String appB = MyFun.nvlStr( request.getParameter("appB"), "") ;
String userA =MyFun.nvlStr( request.getParameter("userA"), "") ;
String userB =MyFun.nvlStr( request.getParameter("userB"), "") ;

%>
<!-- 全局变量 函数定义区 -->
<%!%>
<!-- 实例变量 函数定义区 -->
<%
//网页title
String JSPTITLE = "应用管理";
%>
<%@ include file="pub/head.jsp"%>
<!-- 样式添加区 -->
<link rel="stylesheet" href="<%=basePath%>DataTables/datatables.min.css">
<!-- 下右内容区 -->
<div id="outerdiv"
	style="position: fixed; top: 0; left: 0; background: rgba(0, 0, 0, 0.7); z-index: 999; width: 100%; height: 100%; display: none;">
	<div id="innerdiv" style="position: absolute;">
		<img id="bigimg" style="border: 5px solid #fff;" src="" />
	</div>
</div>

<div class="main-content-inner">
	<div class="breadcrumbs ace-save-state" id="breadcrumbs">
		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i>第三方应用管理</li>
			<li class="active"><%=JSPTITLE%></li>
		</ul>
	</div>
	<div class="page-content">
		<!-- page-header{ -->
		<div class="page-header">
			<!-- table header1{ -->
			<div class="row">
				<div class="col-xs-12">
					<div class="clearfix">
						<div class="pull-right tableTools-container"></div>
						<div class="">
							<div class="btn-group" style="margin-top: 5px">
								<a href="#" class="btn-refresh btn  btn-xs "> <i
									class="im-spinner10 fa-spin"></i> 刷新
								</a> <a data-toggle="collapse" href="#demo" class=" btn  btn-xs ">
									<i class="im-spinner10 fa-spin"></i>搜索
								</a> <a  href="javascript:guanl()" class="btn btn-xs" >
									<i class="im-spinner10 fa-spin"></i>关联
								</a>
							</div>
						</div>
					</div>
					<div id="demo" class="panel-collapse collapse ">
						<div class="panel-body well">
							<form>
								<div class="col-lg-12 col-sm-12  input-group ">
									<input type="text" name="appB" value="<%=appB %>"
										placeholder="应用名称"> <input type="text" name="userA"
										value="<%=userA %>" placeholder="本系统用户账号"> <input
										type="text" name="userB" value="<%=userB %>"
										placeholder="其他系统用户账号">
								</div>
								<div class="col-lg-12 col-sm-12">
									<button type="submit"
										class="btn btn-success btn-sm  pull-right">
										<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
										查找
									</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			<!-- }table -header1  -->
		</div>
		<!-- }page-header  -->

		<!-- table header2{ -->
		<div class="row">
			<div class="col-xs-9 tablehead2L"></div>
			<div class="col-xs-3 tablehead2R"></div>
		</div>
		<!-- }table -header2  -->
		<!--  table { -->
		<div class="row tablexscroll">
			<table id="myTable" class="table table-striped table-bordered"
				cellspacing="0">
				<thead>
					<tr>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>

		</div>
		<!--}table  -->
		<!-- table end{ -->
		<div class="row">
			<div class="col-xs-4"></div>
			<div class="col-xs-8">
				<ul class="pagination"></ul>
				<span class="tablefooterinfo"></span>
			</div>
		</div>
		<!--}table end -->
	</div>
</div>
<!--  footer{ -->
<div class="footer">
	<div class="footer-inner">
		<div class="footer-content  pull_right">
			<span class="bigger-110"> <span class="blue bolder"></span>
			</span>
		</div>
	</div>
</div>
<!--}  footer -->

<a href="#" id="btn-scroll-up"
	class="btn-scroll-up btn btn-sm btn-inverse"> <i
	class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>

<%@ include file="pub/bottom.jsp"%>


<!-- 引入组件库 -->
<script src="<%=basePath%>DataTables/datatables.min.js"></script>
<script src="<%=basePath%>js/hyl.page.js"></script>
<!-- 自定义脚本 加载区 -->

<script>
const JSPTITLE='<%=JSPTITLE%>';
const BASEPATH='<%=basePath%>';
//console.log(BASEPATH + "admin/Dao/app_1.jsp");

function guanl(){
	var app='';
	var usera='<%=tk.getUname()%>';
	var url=BASEPATH + 'admin/appuser_add.jsp?app=' +app+'&usera='+ usera;
	//alert(url);
	window.open(url);
	window.addEventListener('message',function(e){
		// 忽略来自其他域名的跨文档消息（只接受http://localhost:8888的消息）
		//if (ev.origin != "http://localhost:8080") 	
		//	return;
		//console.log(e);
		location.reload();
		
	});
}

function delgx(id){
	var url=BASEPATH + 'admin/Dao/appuser_del.jsp?openid=' +id
 	location.href=url;
	//PG.load();
}
var confg = {
	dom : '',
	renderer : "bootstrap",
	paging : false,
	"ordering" : false,
	"searching" : false,
	"info" : false,
	buttons : [ 'colvis', 'pdf', {
		text : 'My button',
		action : function(dt) {
			console.log('My custom button!');
		}
	} ],
	//stateSave: true, 
	"language" : {
		"lengthMenu" : "每页 _MENU_ 条记录",
		"zeroRecords" : "没有找到记录",
		"info" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
		"infoEmpty" : "无记录",
		"infoFiltered" : "(从 _MAX_ 条记录过滤)"
	//, "decimal": ".", "thousands": "," ,
	},
	//列属性声明

	//a.t0,a.t1,a.t2,a.tm0,a.dt0
	//,a.s0,a.t3,a.id,a.appid
	//render 渲染特定列
	"columnDefs" : [
		{
			title : "关系ID",
			"render" : function(data, type, row) {
				let a =" <a href='' >"+ row[0]+"</a>";						
				return a;
			},
			"targets" : 0
		},	
		{
			title : "应用程序B",
			"render" : function(data, type, row) {
				let a =" <a href='<%=basePath%>sso/a_b.jsp' >"+ row[2] + "</a>";
				return a;
				},
				"targets" : 1
		},
		{
			title : "单点A用户",
			"render" : function(data, type, row) {
				return row[7];
			},
			"targets" : 2
		},
		{
			title : "应用B用户",
			"render" : function(data, type, row) {
				return row[8];
			},
			"targets" : 3
		},
		{
			title : "上一次登录ip",
			"render" : function(data, type, row) {
				return row[5];
			},
			"targets" : 4
		},
		{
			title : "是否有效",
			"render" : function(data, type, row) {
				return row[6];
			},
			"targets" : 5
		},
		{
			title : "操作",
			"render" : function(data, type, row) {
				var id = row[0];
				//alert(flowid);
				var button = '<button class="btn btn-sm btn-success btn-white btn-round " onclick="delgx(\''
						+ id + '\')">删除</button>';
				return button;
			},
			"targets" : 6
		} ],
	"footerCallback" : function(row, data, start, end, display) {
		//汇总统计回调函数

	}
};
var table = $('#myTable').DataTable(confg);
//自定义的分页的函数,名字不要改 确保与page.js中的调用函数名一致;
//载入数据的函数
//传入第几页
var PG = HylPage.getInstance(JSPTITLE);
$(document).ready(
	function() {

	PG.load = function(n) {
		var pgindex = PG.sessionPgIndex();//缓存成上一次定位的页
		if (pgindex && (!n))
			n = pgindex;
		else if ((!pgindex) && (!n)) {
			n = 1;
		}
		//需要传到后台的参数 	
		var data1 = {
			"rs_index" : (n - 1) * PG.pgSize,//从第几条记录开始
			"rs_size" : PG.getMaxRcNum(),//取几条数据过来
			"appB" : $("input[name='appB']").val(),
			"userA" : $("input[name='userA']").val(),
			"userB" : $("input[name='userB']").val()
		};
		//用法: $.post("chargelist2.do", data1).success(function(rs) {});    	
		//解释: (去哪里,要做什么) 成功做完成以后{
		// 返回以后 做什么...
		//}
		$.post(BASEPATH + "admin/Dao/appuser_dao.jsp", data1)					
		.success(
				function(result) {
					console.log(result);
					PG.bind({
						tableobj : table,
						pageobj : $(".pagination"),
						rs : result.BODY._rs,
						pindex : n,
						psize : 0,
						totalnum : result.BODY.total
					});
					if (result.BODY.total
							&& result.BODY.total > 0) {
						$(".tablefooterinfo").html(
								"一共查询到" + result.BODY.total
										+ "条记录");
					}
				});
	}
	PG.load();
	//行点击事件
	$('#myTable tbody').on('click', '.btn-del', function() {
		var qtr = $(this).parent('tr');
		var data = table.row(qtr.get(0)).data();
		//alert('You clicked on ' + data[0] + '\'s row');
	});
	$('#myTable tbody').on('click', '.btn-chg', function() {
		var qtr = $(this).parent('tr');
		var data = table.row(qtr.get(0)).data();
		//alert('You clicked on ' + data[0] + '\'s row');
	});
});
</script>